//
//  ALPS_TListDTCell.m
//  Alps
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TListDTCell.h"

@implementation ALPS_TListDTCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.smallView = [[UIImageView alloc] init];
        self.smallView.layer.masksToBounds = YES;
        self.smallView.layer.borderWidth = 1;
        self.smallView.layer.borderColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.00].CGColor;
        [self.contentView addSubview:_smallView];
        
        self.rankLabel = [[UILabel alloc] init];
        self.rankLabel.textAlignment = 1;
        self.rankLabel.font = [UIFont systemFontOfSize:16];
        self.rankLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_rankLabel];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.numberOfLines = 1;
        self.titleLabel.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:_titleLabel];
        
        self.authorLabel = [[UILabel alloc] init];
        self.authorLabel.font = [UIFont systemFontOfSize:15];
        self.authorLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_authorLabel];
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lineLabel];
        
        self.bluesLabel = [[UILabel alloc] init];
        self.bluesLabel.textColor = [UIColor grayColor];
        self.bluesLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_bluesLabel];

        
        self.albumView = [[UIImageView alloc] init];
        [self.contentView addSubview:_albumView];
        
    }

    return self;
}

-(void)layoutSubviews
{

    [super layoutSubviews];
    [self.rankLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.top.equalTo(self.contentView).offset(0);
        make.width.equalTo(30);
        make.height.equalTo(self.contentView.height);
    }];
    
    [self.smallView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rankLabel.right).offset(0);
        make.top.equalTo(self.contentView).offset(10);
        make.width.equalTo(80);
        make.height.equalTo(80);
        
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(30);
    }];
    
    [self.authorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(5);
        make.left.equalTo(self.smallView.right).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(20);
    }];
    
    [self.lineLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.bottom).offset(-1);
        make.left.equalTo(self.contentView).offset(120);
        make.right.equalTo(self.contentView).offset(0);
        make.height.equalTo(1);
    }];
    
    [self.albumView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.authorLabel.bottom).offset(5);
        make.left.equalTo(self.smallView.right).offset(10);
        make.width.equalTo(20);
        make.height.equalTo(20);
    }];
    
    [self.bluesLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.authorLabel.bottom).offset(5);
        make.left.equalTo(self.albumView.right).offset(5);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(20);
    }];

    
}

-(void)setMdoel:(ALPS_TListDModel *)mdoel
{
    if (_mdoel != mdoel) {
        _mdoel = mdoel;
        
            [self.smallView sd_setImageWithURL:[NSURL URLWithString:self.mdoel.coverSmall] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
            self.titleLabel.text = self.mdoel.title;
            self.authorLabel.text = [NSString stringWithFormat:@"by %@", self.mdoel.nickname];
            self.smallView.layer.cornerRadius = 25;


    }

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
